package com.tsx.response.entity.result;

import com.tsx.response.entity.enums.ReturnCodeEnum;
import lombok.Data;

@Data
public class R<T> {
    private Integer code;
    private String message;
    private T data;

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> R<T> success(T data) {
        return new R<>(ReturnCodeEnum.RC200.getCode(), ReturnCodeEnum.RC200.getMessage(), data);
    }

    public static <T> R<T> error(Integer code, String message, T data) {
        return new R<>(code, message, data);
    }

    public static <T> R<T> error(ReturnCodeEnum returnCodeEnum, T data) {
        return new R<>(returnCodeEnum.getCode(), returnCodeEnum.getMessage(), data);
    }

    public static <T> R<T> error(ReturnCodeEnum returnCodeEnum) {
        return new R<>(returnCodeEnum.getCode(), returnCodeEnum.getMessage(), null);
    }

    public static <T> R<T> error(String message) {
        return new R<>(ReturnCodeEnum.RC500.getCode(), message, null);
    }

    public static <T> R<T> error() {
        return new R<>(ReturnCodeEnum.RC500.getCode(), ReturnCodeEnum.RC500.getMessage(), null);
    }

    public static <T> R<T> error(Integer code, String message) {
        return new R<>(code, message, null);
    }

    public static <T> R<T> error(Integer code) {
        return new R<>(code, ReturnCodeEnum.RC500.getMessage(), null);
    }
}
